package com.chaos.auth.config.userdetails.service;


import com.chaos.auth.config.userdetails.service.common.AdminCommonDetailsService;
import com.chaos.auth.config.userdetails.service.base.UserDetailsExtService;
import com.chaos.system.api.data.RbacUserData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @author Jacky
 */
@Slf4j
@Component
public class AdminByUsernameDetailsService implements UserDetailsExtService {
    @Resource
    private AdminCommonDetailsService adminDetailsBaseService;


    @Override
    public UserDetails loadUserByUsername(String username, Long tenantId) throws UsernameNotFoundException {

        RbacUserData rbacUser = adminDetailsBaseService.getRbacUserDtoByUsername(username, tenantId);
        return adminDetailsBaseService.getAdminUserDetails(rbacUser);
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        RbacUserData rbacUser = adminDetailsBaseService.getRbacUserDtoByUsername(username);
        return adminDetailsBaseService.getAdminUserDetails(rbacUser);
    }

}
